#!/usr/bin/env python
import MySQLdb

host = "localhost"
user = "syn"
passwd = "123456789"
database = "information_schema"
conn = MySQLdb.connection(host,user,passwd,database)

schema = "bookling"

qry = "SELECT ordinal_position, table_name, column_name FROM columns WHERE table_name IN ("  \
        "SELECT table_name FROM tables WHERE table_schema = '" +schema+ "')" \
        "AND table_schema = '" +schema+ "' ORDER BY 2, 1"

f = open('syn','w')
conn.query(qry)
res = conn.store_result()
break_tb = None
for (num, table, col) in res.fetch_row(maxrows=0):
    if break_tb != table:
        break_tb = table
        f.write("******************Tabella : %s \n" % table)
        
    attr = col.replace(table,"",1)
    f.write("%s = Field() \n" % (attr.replace("_","",1)))
f.close()
    
    


